package Solution101_200.problem104.MaximumDepthofBinaryTree;

import common.TreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * @program Leetcode
 * @description:
 * @author: lishangsheng
 * @create: 2019/07/10 20:50
 */
public class Solution {
    public int maxDepth(TreeNode root) {
        if(root==null){
            return 0;
        }
        List<TreeNode> nextLevelNode=new ArrayList<>();
        nextLevelNode.add(root);
        return maxdepth(nextLevelNode,0);
    }

    private int maxdepth(List<TreeNode> nodes,int deep){
        deep=deep+1;
        List<TreeNode> nextLevelNode=new ArrayList<>();
        for(TreeNode node:nodes){
            if(node.left!=null) {
                nextLevelNode.add(node.left);
            }
            if(node.right!=null){
                nextLevelNode.add(node.right);
            }
        }
        if(nextLevelNode.size()==0){
            return deep;
        }
        return  maxdepth(nextLevelNode,deep);

    }
}
